<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 后台管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class=" layui-card-header">
            <button class="layui-btn layuiadmin-btn-admin layui-btn-sm" data-type="add" id="add">添加管理员</button>
        </div>
        <div class="layui-card-body">
            <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
        </div>
    </div>

</div>
</div>
<script type="text/html" id="table-tool">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
            class="layui-icon layui-icon-edit"></i>编辑</a>
    {{# if(!d.supper){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
    {{# } }}
</script>
<script type="text/html" id="roleNameTmp">
    {{# if(d.role){ }}
    <span class="layui-badge layui-bg-blue"> {{ d.role.roleName }}</span>
    {{# }else{ }}
    -
    {{# } }}
</script>

<script type="text/html" id="supperTmp">
    {{# if(d.supper){ }}
    <span class="layui-badge">是</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-blue">否</span>
    {{# } }}
</script>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script src="../../../layuiadmin/lib/juicer-min.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'routerHelper', 'table', 'setter', 'auth', 'layer', 'commonAdmin','AppHelper'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , setter = layui.setter
            , layer = layui.layer
            , routerHelper = layui.routerHelper
            , commonAdmin = layui.commonAdmin
            , AppHelper = layui.AppHelper
            , LayerPage = AppHelper.getLayerPage()
        ;

        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-user-back-manage', {
                where: field
            });
        });

        //管理员管理
        var currentTable = table.render({
            elem: '#LAY-user-back-manage'
            , url: setter.apiHost + '/admin/api/list'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                // , {field: 'id', width: 100, title: 'ID', sort: true}
                , {field: 'loginName', title: '登录名', minWidth: 100}
                , {field: 'roleName', title: '角色名', minWidth: 100, templet: "#roleNameTmp"}
                , {field: 'supper', title: '超级管理员', minWidth: 100, templet: "#supperTmp"}
                , {field: 'nickname', title: '昵称', minWidth: 100}
                , {field: 'mobile', title: '手机'}
                , {field: 'currentLoginTime', width: 120, title: '本次登录时间'}
                , {field: 'lastLoginTime', width: 120, title: '上次登录时间'}
                , {field: 'createTime', width: 120, title: '创建时间'}
                , {title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-tool'}
            ]]
            , page: false
            , limit: 30
            , text: '对不起，加载出现异常！'
            , parseData: function (res) { //res 即为原始返回的数据
                console.log(res)
                return {
                    "status": res.status, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "total": res.data.total, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , response: {
                statusName: 'status' //规定数据状态的字段名称，默认：code
                , statusCode: 200 //规定成功的状态码，默认：0
                , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                , countName: 'total' //规定数据总数的字段名称，默认：count
                , dataName: 'data' //规
            }
        });

        //绑定按钮功能
        table.on("tool(LAY-user-back-manage)", function (obj) {
            var event = obj.event;
            var data = obj.data;

            switch (event) {
                case "edit":
                    var id = data.id;
                    var path = routerHelper.jump({
                        path: "./adminform.html"
                        , query: {
                            id: id,
                            action: "edit"
                        }
                    });

                    LayerPage.open({
                        path : path
                        ,title:"编辑管理员"
                        ,iframeSubmitId:"#adminSubmit"
                    })


                    break;
                case "del":
                    var id = data.id;
                    commonAdmin.delConfirm(id).done(function (res) {
                        currentTable.reload();
                    })
                    break;
            }
        });

        $("#add").on("click", function () {
            var path = routerHelper.jump({
                path: "./adminform.html"
                , query: {
                    action: "add"
                }
            });

            LayerPage.open({
                path:path
                ,title:"新建管理员"
                ,iframeSubmitId:"#adminSubmit"
            })

        })
    });
</script>
</body>
</html>

